Jump to content

form insert help.


techker

Recommended Posts

hey guys im trying to do a select pic to insert the name in a database.

 

the insert works but it does not insert the pic name only an id..

 

i can't seem to figure it out..

 

<? $dbh = mysql_connect("localhost","user","pass") or die("There was a problem with the database connection.");
    $dbs = mysql_select_db("db", $dbh) or die("There was a problem selecting the categories.");

$type=$_POST['type'];


$sql = "SELECT * 
FROM `gymball` 
WHERE `type` = '$type' ";
$fileLIST=mysql_query($sql);?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GymGraph</title>
</head>

<body>


<p align="center"><u>Sélectionner UNE photo</u></p>
<table width="346" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr><? while($row = mysql_fetch_array($fileLIST)) { ?>
    <td width="173"><?php echo '<a href="/Gymgraph/Gymgraph/gymball/'. $row['name'] .'" target="_blank">
<img src="/Gymgraph/Gymgraph/gymball/'. $row['name'] .'" border="0" alt="" width=115/>
</a> 
<br />'; ?></td>
    <td width="173"><label>
      <input type="checkbox" name="select" id="pic" value='<? $row['name'] ?>'/>
    Selection de photo</label></td>
  </tr>
  <? } ?>
</table>
<p>
  <p>
    <label>
    <div align="center">
      <select name="location" id="location">
        <option value="pic1">1</option>
        <option value="pic2">2</option>
        <option value="pic3">3</option>
        <option value="pic4">4</option>
        <option value="pic5">5</option>
        <option value="pic6">6</option>
        <option value="pic7">7</option>
        <option value="pic8">8</option>
      </select> 
      Emplacement de la photo
    </div>
    </label>
  </p>
  <label>
  <div align="center">
    <input type="submit" name="submit" id="submit" value="Submit" />
  </div>
  </label>
  <div align="center">  Envoyer la sélection
  </div>
</p>
</form>
</body>
</html>

 

and this is the insert pic

<?php

 

$pic=$_POST['pic'];

$location=$_POST['location'];

 

 

 

mysql_connect("localhost", "user", "t") or die(mysql_error()) ;

mysql_select_db("techker_gymgraphpics") or die(mysql_error()) ;

 

 

 

//Writes the information to the database

mysql_query("INSERT INTO $location (name) ".

        "VALUES ('$pic')");

 

 

//Tells you if its all ok

$id= mysql_insert_id();

    echo "<p>This file has the following Database ID: <b>$id</b>";

echo "You'll be redirected to Home Page after (4) Seconds";

          echo "<meta http-equiv=Refresh content=4;url=gymball_select.php>";

 

?>

Link to comment
https://forums.phpfreaks.com/topic/135496-form-insert-help/
Share on other sites

Use mysql_error() after your query to check for errors

 

Are you saying this isn't working?

 

mysql_query("INSERT INTO $location (name) ".

        "VALUES ('$pic')");

 

if so, echo $location and $pic to make sure the are what they should be.

Link to comment
https://forums.phpfreaks.com/topic/135496-form-insert-help/#findComment-705888
Share on other sites

first off i ma not sure if you mean radio instead of check boxes but in anycase you have 2 problems

1. you requesting $_POST['pic']; which is the ID not the name.. the name is "select"

2. it will only take the last ticked value..

 

so to fix this.. change

<input type="checkbox" name="select" id="pic" value='<? $row['name'] ?>'/>

to

<input type="checkbox" name="pic[]" id="pic" value='<?php $row['name'] ?>'/>

 

and then

change

$pic=$_POST['pic'];

to

$pic=$_POST['pic'][0]; //assuming you only tick 1 box

Link to comment
https://forums.phpfreaks.com/topic/135496-form-insert-help/#findComment-705889
Share on other sites

first off i ma not sure if you mean radio instead of check boxes but in anycase you have 2 problems

1. you requesting $_POST['pic']; which is the ID not the name.. the name is "select"

2. it will only take the last ticked value..

 

so to fix this.. change

<input type="checkbox" name="select" id="pic" value='<? $row['name'] ?>'/>

to

<input type="checkbox" name="pic[]" id="pic" value='<?php $row['name'] ?>'/>

 

and then

change

$pic=$_POST['pic'];

to

$pic=$_POST['pic'][0]; //assuming you only tick 1 box

 

so what would be the value?i need the named of the image that is ticked.

whats the [0] added?

Link to comment
https://forums.phpfreaks.com/topic/135496-form-insert-help/#findComment-706272
Share on other sites

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.