variable passing

0 reema dawes · September 11, 2014
<form action="page2.php" method="post">
title <input type="text" name="title" >
content <input type="text" name="content">
homepage <input type="checkbox" name="chk" value="yes">
<input type="submit" name="submit" value="submit">
<?php
if (isset($_POST['submit']))
$title= $_POST['title'];
$content=$_POST ['content'];
$chk=$_POST['chk'];
if ( $title=='' or $content==''){
echo"enter all fields";
}
else {
$query=INSERT into posts VALUE ('',$title,'$content,'')
}
if ($query_run=mysql_query($query) {
echo "successful";
}

if (isset($_POST['chk'])&& $chk=='yes'))
while ($row=mysql_fetch_assoc($query_run)){
echo "<a href=\"index.php?id=".$row['id']."/> </a>";
}





?>

Post a Reply

Replies

- page 1
Oldest  Newest  Rating
+1 Franz Schmidt · September 11, 2014
What is with this code?
0 reema dawes · September 12, 2014
i am trying to get the specific data of the column id from the database if the checkbox is clicked, so the information should pass to index.php otherwise it just inserts into the database.
+1 Franz Schmidt · September 12, 2014
And whats your problem?
0 reema dawes · September 12, 2014
my problem is the data isn't being passed to the index.php page, it does the insert into the database but when i go to index.php its blank
+1 JOhaL jaTT · September 12, 2014
try this  


id =   $row['id'];

echo '<a href="index.php?id='.$id.' ">'.$id.' </a>'; 



if you tell me about sql table structure then i will help you more also index page
and one thing i mast consider OR  EXPRESSION 


HERE 
if ( $title=='' or $content=='') it mast be    if ( $title=='' || $content=='')

use OR EXPRESSION ( ||  )  instead of word  "or"
+1 Franz Schmidt · September 12, 2014
Could you post your index.php to?
0 reema dawes · September 12, 2014
mysql table structure is 
id    title    content      with id being the primary key which auto increments 
0 JOhaL jaTT · September 12, 2014
Posting error
0 JOhaL jaTT · September 12, 2014
Alright this works but chat section not working
0 JOhaL jaTT · September 12, 2014
Here we go 
Copy and paste if you need any help just message me 

NOTE :>>>> SAVE  AS index.php

Hope it  helps you.




<html>
<head>
<title>Power of Code</title>

</head>
<body>
<form action="index.php" method="POST">
title <input type="text" name="title" >
content <input type="text" name="content">
homepage <input type="checkbox" name="chk" value="1">
<input type="submit"  value="submit">
</form>
</body>
</html>
<?php
//CONNECT TO DATABASE
include_once('connect.php');
if (isset($_POST['chk'])){
$title= $_POST['title'];
$content=$_POST ['content'];
$chk=$_POST['chk'];
if ( $title=="" || $content==""  ){
echo"enter all fields";
exit();
}
else {
//INSERT DATA TO DATABASE
$sql = "INSERT INTO reema (title,content) VALUES('$title','$content')";
$query = mysqli_query($db_conn,$sql) or die(mysqli_error());
//FETCH LAST INSERTED ID DATA FROM DATABASE 
$sql = "SELECT * FROM reema where id= LAST_INSERT_ID() LIMIT 1 ";
$query = mysqli_query($db_conn,$sql) or die(mysqli_error());
while ($row=mysqli_fetch_assoc($query)){
$id = $row['id'];
$title = $row['title'];
$content = $row['content'];
echo "id ".$id."<br />";
echo "title ".$title."<br />";;
echo "content ".$content."<br />";;
}
echo '<a href="index.php">Back To Home</a>';
}
}
?>
  • 1
  • 2

PHP

107,175 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators