Jump to content

[SOLVED] PHP and SQL problem


grahamb314

Recommended Posts

The following code is supposed to insert some data from the previous page into the database. It doesnt show any errors and no data goes into the database!?

 

Any

  Quote
<?php

 

require_once 'mysql_connect.php';

$query = "SELECT * FROM `grahamb_test`.`schedule` WHERE `Show` = '{

$_POST["Show"]}';";

$result = mysqli_query($mysqli, $query) or die("Query:{$query} <br>Error:".mysqli_error($mysqli));

echo "rows = ".mysqli_num_rows($result);

 

if (mysqli_num_rows($result) >= 1) {

echo "This show name already exists";

 

}

else {

$sql = mysqli_query($mysqli, "INSERT INTO `grahamb_test`.`schedule` (`ID`, `Show`, `StartTime`, `EndTime`, `Day`, `Type`, `Page`, `Profile_url` ) VALUES (NULL,'".$_POST["Show"]."','".$_POST["StartTime"]."','".$_POST["EndTime"]."''".$_POST["Day"]."','".$_POST["Type"]."','".$_POST["Page"]."','".$_POST["Profile_url"]."')");

 

echo "<p>The show <b> ". $_POST["Show"] ." </b>has been added to the database!";

}

 

?>

Link to comment
https://forums.phpfreaks.com/topic/124224-solved-php-and-sql-problem/
Share on other sites

Add

 

or die("Query:{$query} Error:".mysqli_error($mysqli)); 

 

to

 

$sql = mysqli_query($mysqli, "INSERT INTO `grahamb_test`.`schedule` 
(`ID`, `Show`, `StartTime`, `EndTime`, `Day`, `Type`, `Page`, `Profile_url` )
VALUES
(NULL,'".$_POST["Show"]."','".$_POST["StartTime"]."','".$_POST["EndTime"]."''".$_POST["Day"]."','".$_POST["Type"]."','".$_POST["Page"]."','".$_POST["Profile_url"]."')");

 

 

That would tell you have a missing comma here

 

$_POST["EndTime"]."''".$_POST["Day"].

 

You could actually write this query like this:

 

$sql = mysqli_query($mysqli, "INSERT INTO `grahamb_test`.`schedule` 
( `Show`, `StartTime`, `EndTime`, `Day`, `Type`, `Page`, `Profile_url` )
VALUES
('{$_POST["Show"]}','{$_POST["StartTime"]}','{$_POST["EndTime"]}','{$_POST["Day"]}','{$_POST["Type"]}','{$_POST["Page"]}','{$_POST["Profile_url"]}')");

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.